/*
	[OElove] (C)2006-2011 OE Development team Inc.
	This is NOT a freeware, use is subject to license terms
	$Id: area.js 2011-10-18 XiangFeng $
*/

/*
  $Id    : jquery for ajax 获取所在地区子分类
  @params: parentselectname 父类 SELECT ID
  @params: childselectname 子类 SELECT 名
  @params: childvalue 子类值
  @params: showspread 是否显示扩展名
  @params: jsonid AJAX返回的JSON
*/
function fetch_city(parentselectname,childselectname,childvalue,showspread,jsonid){
	var parentvalue = $("#"+parentselectname).val();
	if(parentvalue>0){
		$.getJSON(_ROOT_PATH+"data/ajax/getcity.php?rootid="+parentvalue+"&showspread="+showspread+"&rnd="+new Date().toString(),
			function(data){
				var option_html = "";
				$.each(data,function(entryIndex,entry){
					option_html += "<option value='"+entry.areaid+"'";
					if(childvalue==entry.areaid){
						option_html += "selected";
					}
					option_html += ">"+entry.areaname+entry.spreadname+"</option>";
				});
				option_html = "<select name='"+childselectname+"' id='"+childselectname+"'><option value=''>　　</option>"+option_html+"</select>";
				$("#"+jsonid).html(option_html);
			}
		);
	}else{
		$("#"+childselectname).find("option").remove();
	}
}

/*
  $Id    : jquery for ajax 获取户籍子地区
  @params: parentselectname 父类 SELECT ID
  @params: childselectname 子类 SELECT 名
  @params: childvalue 子类值
  @params: showspread 是否显示扩展名
  @params: jsonid AJAX返回的JSON
*/
function fetch_hometown(parentselectname,childselectname,childvalue,showspread,jsonid){
	var parentvalue = $("#"+parentselectname).val();
	if(parentvalue>0){
		$.getJSON(_ROOT_PATH+"data/ajax/gethometown.php?rootid="+parentvalue+"&showspread="+showspread+"&rnd="+new Date().toString(),
			function(data){
				var option_html = "";
				$.each(data,function(entryIndex,entry){
					option_html += "<option value='"+entry.areaid+"'";
					if(childvalue==entry.areaid){
						option_html += "selected";
					}
					option_html += ">"+entry.areaname+entry.spreadname+"</option>";
				});
				option_html = "<select name='"+childselectname+"' id='"+childselectname+"'><option value=''>　　</option>"+option_html+"</select>";
				$("#"+jsonid).html(option_html);
			}
		);
	}else{
		$("#"+childselectname).find("option").remove();
	}
}